package com.hongzhimei.yukicomic.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * SharedPreference工具类
 */

public class SPUtils {

    /**
     * SharedPreference存储int
     * @param context
     * @param key
     * @param value
     */
    public static void putInt(Context context,String key,int value){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(key,value);
        editor.commit();
    }

    /**
     * SharedPreference获取int，默认返回值为-1
     * @param context
     * @param key
     */
    public static int getInt(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getInt("key",-1);
    }


    /**
     * SharedPreference存储String
     * @param context
     * @param key
     * @param value
     */
    public static void putString(Context context,String key,String value){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key,value);
        editor.commit();
    }

    /**
     * SharedPreference获取String，默认返回值为""
     * @param context
     * @param key
     */
    public static String getString(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getString("key","");
    }

    /**
     * SharedPreference存储boolean
     * @param context
     * @param key
     * @param value
     */
    public static void putBoolean(Context context,String key,boolean value){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(key,value);
        editor.commit();
    }

    /**
     * SharedPreference获取String，默认返回值为false
     * @param context
     * @param key
     */
    public static boolean getBoolean(Context context,String key){
        SharedPreferences sp = context.getSharedPreferences("config",Context.MODE_PRIVATE);
        return sp.getBoolean(key,false);
    }
}



































































































